<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" import="java.sql.*" import="Connect.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
<title>Hammer Time Auctions</title>
</head>
<body>
	<div id="content">
		<%@include file="header.jsp"%>
		<h1>Success</h1>
		<hr></hr>
		<%
			String username = request.getParameter("username");
			String redirect = "index.jsp";
			if (username == null) {
				out.println("No username was specified to be deleted.<br /> Did you get here by accident? <br /> You will be redirected to the home page. <br />");
			} else {

				// Delete the user from all tables.
				java.sql.Connection conn = null;
				try {
					// Connect to the database.
					Class.forName(ConnectionInfo.myJDBCDriver()).newInstance();
					java.util.Properties sysprops = System.getProperties();
					sysprops.put("user", ConnectionInfo.myUserID());
					sysprops.put("password", ConnectionInfo.myPassword());
					conn = java.sql.DriverManager.getConnection(ConnectionInfo.myURL(), sysprops);

					// Delete the username from the employees, customers, and users table.
					java.sql.Statement statement = conn.createStatement();
					int employee = statement.executeUpdate("DELETE FROM employees WHERE username ='" + username + "'");
					int customer = statement.executeUpdate("DELETE FROM customers WHERE username ='" + username + "'");
					int user = statement.executeUpdate("DELETE FROM users WHERE username ='" + username + "'");
					if (customer > 0) {
						out.println(username + " was removed from the database.<br />You will be redirected in 5 seconds.<br />");
						redirect = "manage_customers.jsp";
					} else if (employee > 0) {
						out.println(username + " was removed from the database.<br />You will be redirected in 5 seconds.<br />");
						redirect = "manage_employees.jsp";
					} else if (user == 0) {
						out.println(username + " was not found in the database.<br /> You will be redirected in 5 seconds.<br />");
					}
				} catch (Exception e) {
					e.printStackTrace();
				} finally {
					try {
						conn.close();
					} catch (Exception ee) {
					}
				}
			}
			out.println("<a href=\"" + redirect + "\">Click here if you can't wait!</a>");
			response.setHeader("Refresh", "5; " + redirect);
		%>
	</div>
	<hr></hr>
	<%@include file="footer.jsp"%>
</body>
</html>